using MyDapperApi.Models;
using MyDapperApi.Repositories.Interfaces;

namespace MyDapperApi.Services;

public class UserService : IUserService
{
    private readonly IUserRepository _userRepository;

    public UserService(IUserRepository userRepository)
    {
        _userRepository = userRepository;
    }

    public async Task<IEnumerable<User>> GetAllUsersAsync() => await _userRepository.GetAllAsync();

    public async Task<User?> GetUserByIdAsync(int id) => await _userRepository.GetByIdAsync(id);

    public async Task<User?> GetUserByEmailAsync(string email) => await _userRepository.GetUserByEmailAsync(email);

    public async Task<int> CreateUserAsync(User user) => await _userRepository.AddAsync(user);

    public async Task<int> UpdateUserAsync(User user) => await _userRepository.UpdateAsync(user);

    public async Task<int> DeleteUserAsync(int id) => await _userRepository.DeleteAsync(id);

    public async Task<IEnumerable<User>> GetUsersByAgeRangeAsync(int minAge, int maxAge)
        => await _userRepository.GetUsersByAgeRangeAsync(minAge, maxAge);
}